# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from os.path import basename,dirname,join
from  urllib.parse import urlparse

import requests
from scrapy.pipelines.files import FilesPipeline
from itemadapter import ItemAdapter


class MyFilesPipeline(FilesPipeline):
    def file_path(self, request, response=None, info=None, *, item=None):
        download_url = request.url
        path = urlparse(download_url)
        return join(basename(dirname(path))),basename((path))
